package cn.stylefeng.guns.modular.productfunction.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.productfunction.entity.ShiHeadFunction;
import cn.stylefeng.guns.modular.productfunction.entity.ShiWhether;
import cn.stylefeng.guns.modular.productfunction.model.params.ShiHeadFunctionParam;
import cn.stylefeng.guns.modular.productfunction.service.ShiHeadFunctionService;
import cn.stylefeng.guns.modular.productfunction.service.ShiWhetherService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

import static cn.stylefeng.roses.core.reqres.response.ResponseData.DEFAULT_SUCCESS_CODE;


/**
 * 控制器
 *  头部功能表
 * @author 石博士
 * @Date 2019-07-05 14:38:37
 */
@Controller
@RequestMapping("/shiHeadFunction")
public class ShiHeadFunctionController extends BaseController {

    private String PREFIX = "/Shiproductfunction/shiHeadFunction";

    @Autowired
    private ShiHeadFunctionService shiHeadFunctionService;

    @Autowired
    private ShiWhetherService shiWhetherService;

    /**
     * 跳转到主页面
     *
     * @author 石博士
     * @Date 2019-07-05
     */
    @RequestMapping("/index")
    public String index() {
        return PREFIX + "/shiHeadFunction.html";
    }

    /**
     * 新增页面
     *
     * @author 石博士
     * @Date 2019-07-05
     */
    @RequestMapping("/add")
    public String add(Model model) {
        List<ShiWhether> shiWhetherList = shiWhetherService.findListBySpec(null);
        model.addAttribute("shiWhetherList", shiWhetherList);
        return PREFIX + "/shiHeadFunction_add.html";
    }

    /**
     * 编辑页面
     *
     * @author 石博士
     * @Date 2019-07-05
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/shiHeadFunction_edit.html";
    }

    /**
     * 新增接口
     *
     * @author 石博士
     * @Date 2019-07-05
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(ShiHeadFunctionParam shiHeadFunctionParam) {
        ShiHeadFunction headFunction = this.shiHeadFunctionService.add(shiHeadFunctionParam);
        return new ResponseData(true, DEFAULT_SUCCESS_CODE, "请求成功", headFunction);
    }

    /**
     * 编辑接口
     *
     * @author 石博士
     * @Date 2019-07-05
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(ShiHeadFunctionParam shiHeadFunctionParam) {
        this.shiHeadFunctionService.update(shiHeadFunctionParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author 石博士
     * @Date 2019-07-05
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(ShiHeadFunctionParam shiHeadFunctionParam) {
        this.shiHeadFunctionService.delete(shiHeadFunctionParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author 石博士
     * @Date 2019-07-05
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(ShiHeadFunctionParam shiHeadFunctionParam) {
        ShiHeadFunction detail = this.shiHeadFunctionService.getById(shiHeadFunctionParam.getId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author 石博士
     * @Date 2019-07-05
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(ShiHeadFunctionParam shiHeadFunctionParam) {
        return this.shiHeadFunctionService.findPageBySpec(shiHeadFunctionParam);
    }

}


